/** \file    luv_color.h
  * \brief   Everything concerning Luv color system.
  * \date    2002
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/include/imglib/luv_color.h,v 1.1 2004/02/04 14:43:24 cscom1r4 Exp $
  */

#ifndef _Luv_color_h_
#define _Luv_color_h_

#include "imglib/imageclass_decl.h"

namespace img {

///extracts two components of the (complex) chromaticity from a color
template <class C>
inline complex_color Luv_chromaticity(const C &c)
{
	double denom = 
		3.14455 * c.r +
		12.526  * c.g +
		3.32945 * c.b;
	if (denom != 0.0)
		denom = 1.0 / denom;

	return complex_color(
		(1.96*c.r + 1.24*c.g + 0.8*c.b) * denom - 0.1978,
		(1.59273*c.r + 7.3116*c.g + 0.09567*c.b) * denom - 0.4683);
}

///extracts lightness component from a color
template <class C>
inline double Luv_lightness(const C &c)
{
	double frac_y = (0.17697*c.r + 0.81240*c.g + 0.01063*c.b) / 255.0;
	if (frac_y > 0.008856)
		return 116.0 * frac_y*frac_y*frac_y - 16.0;
	else
		return 903.3 * frac_y;
}

} //namespace img

#endif //_Luv_color_h_
